home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 265_01 / portable.doc < prev    next >
Text File  |  1990-02-13  |  4KB  |  107 lines

  1. < Portability Note >
  2.  
  3. 1. Compiling cpio programs
  4.  
  5.     John Snaider and Rainer Gerhaldt have submitted public domain
  6.     cpio program. We have compiled their prorgams under MSDOS using
  7.     five popular commercial compilers listed below:
  8.  
  9.     Microsoft C ver. 5.0
  10.     Microsoft C ver. 4.0
  11.     Eco C ver. 3.23
  12.     Turbo C    ver. 1.5
  13.     Lattice C ver. 3.21
  14.  
  15.     The result of compiling indicates that Rainser's cpio (CUGCPIO) is more
  16.     portable than John's cpio (CCPIO). However, this is only because John
  17.     Snaider uses Proposed ANSI functions and reseved words, which some
  18.     compiler vendors don't support yet, and also the compiler vendors
  19.     inconsistently provide different features for their compilers.
  20.  
  21.     In order to make CCPIO and CUGCPIO more protable, we made some
  22.     addition to the programs. All the addition is surrounded by
  23.     preprocessor directives (#if and #endif) so that you will be able
  24.     to compile the programs with a little effort if you pick one of five
  25.     compilers listed above. If you have a compiler not listed above,
  26.     first, go ahead, try to compile with the default settings and see
  27.     what error message you get. And then, determine what corrections
  28.     you need to make. If you have trouble, please feel free to ask us.
  29.  
  30. 2. Compiling CCPIO.C 
  31.  
  32.     At the beginning of the program, you will see five #define directives.
  33.     Those indicate which compiler you are using. For example, if you are
  34.     using Microsoft ver. 5.0, they should look like this:
  35.  
  36.     #define MSC5    1
  37.     #define MSC4    0
  38.     #define LAT3    0
  39.     #define TURBO    0
  40.     #define ECOC    0
  41.  
  42.     The following explains what addition we made to get the program
  43.     compiled under a certain compiler.
  44.  
  45. (Microsoft C ver. 5.0)
  46.  
  47.     John Snaider wrote this program under this compiler.
  48.     
  49. (Microsoft C ver. 4.0)
  50.  
  51.     The only difference between MSC5 and MSC4 is that MSC4 doesn't
  52.     support Proposed ANSI keyword "const". Therfore, "const" is
  53.     defined as nothing. (#define const )
  54.  
  55. (Turbo C ver. 1.5)
  56.  
  57.     Turbo C is very compatible with Microsoft C. No changes.
  58.  
  59. (Lattice C ver. 3.21)
  60.  
  61.     John Snaider uses va_start() and vfprintf() in function error(),
  62.     which displays a formatted error message and terminates the program.
  63.     The varargs facility provides programmers a portable way to access
  64.     the arguments of a fucntion when the fuction takes a variable number
  65.     of arguments. There are two versions of varargs facility: one is 
  66.     compatible with UNIX System V and defined in "varargs.h" and the 
  67.     other is adapted by Draft Proposed ANSI C and defined in "stdarg.h".
  68.     Unfortunately, Lattice C doesn't support this facility in either
  69.     form. To simulate this facility, we had to use very low-level function
  70.     _pf(), which Lattice C uses internally to implement printf style
  71.     functions. _pf() takes a variable number of arguments and writes a
  72.     formatted string to the stream.
  73.     _pf () takes four argumens: display function name, stream, format
  74.     string, and address of first argument.
  75.  
  76. (Eco C)
  77.      
  78.     In the program, there are two functions that Eco C libarary doesn't 
  79.     support. One is access() that checks the accesibility of a file.
  80.     Since this function is used to check only if the target file exsists,
  81.     access() is replaced with !fopen(). The other one is filelength() which
  82.     returns the file length, in bytes, of the target file handle. This
  83.     problem is solved by the combination of fseek() and ftell().
  84.     Also, we have discovered that Eco C compiler doesn't write a NULL
  85.     character to the stream when %c is used in fprintf() and NULL is given
  86.     as its argument. This is a serious bug. However, because fputc() does 
  87.     write a NULL character to the stream, the macro phead is redefined
  88.     to call fputc() and write a NULL character.
  89.  
  90. 3. Compiling CUGCPIO.C
  91.  
  92.     Compiling CUGCPIO.C is much easier than compiling CCPIO.C.
  93.     Rainer Gerhards uses functions widely supported by compiler vendors
  94.     and also provides a header file "environ.h" with the environment
  95.     dependent information.
  96.     Indeed, to adapt this program for ECO C, we needed to change only the
  97.     header file, not the souce code CUGCPIO.C.
  98.     To compile with ECO C compiler, change the setting of target compiler
  99.     to the following:
  100.  
  101.     #define MSC        0
  102.     #define ECOC        1
  103.     #define AUTO_SET    1
  104.     
  105.  
  106.     
  107.